
#include "LPC23xx.h" 
#include "Init.h" 
#include "OS.h" 
#include "Sys.h" 
#include "SysClock.h" 
#include "VCom.h" 
#include "cmdp.h" 
#include "USART.h" 
#include "debug.h" 
#include "sim.h" 
#include "modem.h" 
#include "isd.h" 
#include "dtmf.h" 
#include "Receivers.h" 
#include "ex_eeprom.h" 
#include "iflash.h" 
#include "app_menu.h" 
#include "entrys.h" 
#include "outp_drv.h" 
#include "Config.h" 
#include "hardware.h"
#include "Analog.h"

#define IRQ_RAM_ADDR        0x40000018
#define FIQ_RAM_ADDR        0x4000001C
#define IRQ_RAM_FUNC_ADDR   0x40000038
#define FIQ_RAM_FUNC_ADDR   0x4000003C

void power_down ( int mode );
void power_down ( int mode )
{
	PCON = 0x02;
}

void app_c15 ( void );			  /* app.c */

void Init_Device ( void )
{
	unsigned int * ptr;

   Disable_interrupts();

	sysInit();

   MEMMAP = 0x1;
 

//   Init_CRC32_Table();

  //---- Set interrupts vectors
   ptr = (unsigned int *)IRQ_RAM_ADDR;
   *ptr = 0xE59FF018;                       //-- ldr pc, [pc, #24]
   ptr = (unsigned int *)FIQ_RAM_ADDR;
   *ptr = 0xE59FF018;                       //-- ldr pc, [pc, #24]

   //--- Put IRQ & FIQ vectors in RAM
   ptr = (unsigned int *)IRQ_RAM_FUNC_ADDR;
   *ptr = (unsigned int)&cpu_irq_isr;
   ptr = (unsigned int *)FIQ_RAM_FUNC_ADDR;
   *ptr = (unsigned int)&cpu_fiq_isr;

	/* ============ */
	/* ============ */


	/* power_down(0);  2 */
	
	
	WDT_Init(10);
	SysTimer_Init(SYS_CLOCK__TIMER_0_INTERVAL);
	OS_Init();
	Init_UARTs();

	DBG("\n ====  MAIN PROG ====\n");
	DBG("\n == INITIALIZATION ==\n");

	receivers_init();
	Ex_EEPROM_Init();

	/* SIM_Init(); */
	/* SIM_Select(SIM_INTERNAL_A); */

//	power_down(0);  //4

	/* isd_init(); */
	/* dtmf_init(); */

//	power_down(0);  //5
	
	/* Outputs_Init(); */
	/* AA_Config_Init(); */

	Out_Init();

	fm_check_boot();
//	entrys_init();

	//AnalogInit();

	OS_Run_App(cmd_processor);
	OS_Run_App(app_c15);
	/* OS_Run_App(Modem_Init); */

	//power_down(0);  //3
	
	USB_Start();

	Enable_interrupts();

} 
